<?php

namespace App\Api\V1\Controllers;


//测试类
use App\Events\PushEvent;
use App\exption\push\Hpush\Hpush;
use App\exption\push\Push;
use App\Jobs\Elesticsearch;
use App\Jobs\LogQueue;
use App\Jobs\PushQueue;
use App\Models\Friend;
use App\Models\FriendModel;
use App\Models\FriendUser;
use App\Models\JpushMobile;
use App\Models\Media;
use App\Models\MediaComment;
use App\Models\MemberShip;
use App\Models\Shareholder;
use App\Models\User;
use App\Services\Behavior;
use App\Services\MyElasticSearch;
use App\Services\PushService;
use Elasticsearch\ClientBuilder;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Redis;
use Illuminate\Http\Request;
use OSS\Core\OssException;
use OSS\OssClient;
use App\Models\ES\User AS esUser;
use App\exption\hx_im\Hxim;
use App\Models\HxUsers;


class TestController extends CommonController
{
    public function __construct()
    {
        parent::__construct();
        // 获取用户基本信息
        $this->getUserInfo(false);
    }

    /*
     * 取消无效的亲友
     * 同步亲友圈
     * */
    public function sync_friend()
    {
        $list = FriendModel::where([['status', '=', '1']])->get();
        foreach ($list as $value){
            $userRows = User::where([['id', '=', $value->uid]])->first();
            // 过滤为空的无效用户
            if(empty($userRows)){
                $update = DB::update("update friend set status=0 where uid=".$value->uid." and friend_uid=".$value->friend_uid);
                $updatea = DB::update("update friend set status=0 where friend_uid=".$value->uid." and uid=".$value->friend_uid);
				continue;
            }

            // 同步添加
            $friend = FriendModel::where([['uid', '=', $value->friend_uid],['friend_uid', '=', $value->uid]])->first();
            if(empty($friend)){
                $friend = new FriendModel();
                $friend->uid = $value->friend_uid;
                $friend->friend_uid = $value->uid;
                $friend->status = 1;
                $friend->created_at = $value->created_at;
                $friend->updated_at = $value->updated_at;
                $friend->save();
            }else{
                if($friend->status == '0'){
                    $friend->status = 1;
                    $friend->save();
                }
            }

        }

        return json_success(['ok']);
    }

    /*
     * app 推送测试
     * */
    public function pushTest()
    {

        $error = [];

        $content = IT('content', 'test');
        $type = (int) IT('type', 1);
        $pushParams['channel_id'] = (int) IT('channel_id', 1);
        $id = IT('id', '');
        $push_type = IT('push_type');

        $pushObj = new PushService();
        // 区分应用渠道推送
        $data = $pushObj->initInstance(['channel_id'=>$pushParams['channel_id']]);

        $post_params['title'] = $content;
        $post_params['content'] = $content;
        $post_params['description'] = $content;
        // 消息类型：1通知，0透传
        $post_params['msg_type'] = $push_type;
        // 发送业务id ，id的作用，同一重复发送覆盖，具体结合推送平台文档操作
        $post_params['notify_id'] = $type;
        // 可选项
        // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
        $post_params['notify_foreground'] = 0;

        $post_params['mobile_list'] = $id;

        $data = $pushObj->singlePush($post_params);
        if($data['status'] == 'error')
            $error[] = $data['message'];
        if(!empty($error))
            dd($error);
        return json_success('ok', $data);
    }

    /*
     * 清空股东申请信息
     * */
    public function create_shareholder(Request $request)
    {

        $mobile = IT('mobile', true, '手机号必填');

        $model = Shareholder::where([['mobile', '=', $mobile], ['status', '=', '0']])->first();

        if(!empty($model)){

            $model->id_card = null;
            $model->address = null;
            $model->positive_card = null;
            $model->opposite_card = null;
            $model->bank_number = null;
            $model->bank_name = null;
            $model->opening_bank = null;
            $model->operation_status = 0;
            $model->sign_img = null;
            $model->shareholder_agree_img = null;
            $model->local_agree_img = null;
            $model->shareholder_certificate_img = null;
            $model->local_certificate_img = null;

            if($model->save()){
                return json_success(['操作成功']);
            }
            return json_error(['操作异常']);
        }else{
            return json_error(['股东不存在']);
        }

    }

    /*
     * 清会员信息
     * */
    public function clen_member(Request $request)
    {
        $mobile = IT('mobile', true, '手机号必填');
        $model = MemberShip::where([['mobile', '=', $mobile], ['status', '=', '0']])->first();
        if(!empty($model)){
            $model->avatar = null;
            $model->certificate = null;
            $model->member_avatar = null;
            $model->member_avatar = null;

            if($model->save()){
                return json_success(['操作成功']);
            }
            return json_error(['操作异常']);
        }else{
            return json_error(['股东不存在']);
        }

    }

    /*
     * 清微信
     * */
    public function clen_wx_user(Request $request)
    {
        $id = $request->get('id');
        $userModel = User::where([['id', '=', $id]])->first();
        if(empty($userModel))
            return json_error('用户不存在');
        
        $userModel->openid = '';
        $userModel->app_openid = '';
        $userModel->openid_default = '';
        $userModel->unionid = '';
        $userModel->save();

        if($userModel->save())
            return json_success('0k');
        return json_success('0k');
    }

    /*
     * 单个推送
     * */
    public function singlePush($type, $pushParams)
    {
        $error = [];
        // 检查基础参数
        if(!isset($pushParams['channel_id']) || !isset($pushParams['title']) ||  !isset($pushParams['content']) ||  !isset($pushParams['description'])
            || !isset($pushParams['msg_type']) || !isset($pushParams['notify_id']) || !isset($pushParams['notify_foreground']))
            $error[] = '参数异常1';
        if(!isset($pushParams['mobile_list']))
            $error[] = '未知推送用户';

        // 执行推送
        if(empty($error)){
            $pushObj = new PushService();
            // 区分应用渠道推送
            $data = $pushObj->initInstance(['channel_id'=>$pushParams['channel_id']]);

            $post_params['title'] = $pushParams['title'];
            $post_params['content'] = $pushParams['content'];
            $post_params['description'] = $pushParams['description'];
            // 消息类型：1通知，0透传
            $post_params['msg_type'] = $pushParams['msg_type'];
            // 发送业务id ，id的作用，同一重复发送覆盖，具体结合推送平台文档操作
            $post_params['notify_id'] = $pushParams['notify_id'];
            // 可选项
            // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
            $post_params['notify_foreground'] = $pushParams['notify_foreground'];
            if(isset($pushParams['bi_tag']) && !empty($pushParams['bi_tag']))
                $post_params['bi_tag'] = $pushParams['bi_tag'];
            if(isset($pushParams['icon']) && !empty($pushParams['icon']))
                $post_params['icon'] = $pushParams['icon'];
            $post_params['mobile_list'] = $pushParams['mobile_list'];

            $data = $pushObj->$type($post_params);
            if($data['status'] == 'error')
                $error[] = $data['message'];
        }

        if(!empty($error))
            return ['status'=>'error', 'message'=>implode(',', $error)];
        return ['status'=>'success', 'message'=>'执行成功'];
    }

    function arrayToTree2(Array $items) {
        $tree = array();
        foreach ($items as $item)
            if (isset($items[$item['parent_id']])) {
                $items[$item['parent_id']]['son'][] = &$items[$item['id']];
            } else {
                $tree[] = &$items[$item['id']];
            }
        return $tree;
    }

    /*
     * 框架压力测试
     * */
    public function pres_frame()
    {
        return json_success('ok');
    }

    //首页
    public function index(Request $request)
    {
        dd(md5('你好'));
        $media_id = 1794;
        $option_uid = 8272849;
        $key = 'media:star:m_'.$media_id.'_u_'.$option_uid;

        dd(Redis::get($key));
        $a[] = ['a'=>'a', 'b'=>'b'];
        array_unshift($a, ['c'=>'c']);
        dd($a);

        $where['a'] = 'ca';
        $where['b'] = 'b';

        dd();
        dd(rand(3600, 7200));
        $rand = rand(3600, 7200);

        App::setLocale('en');

        dd(trans('admin.100000'));
       

        $host = getenv("ELASTICSEARCH_HOST");
        $port = getenv("ELASTICSEARCH_PORT");

        $client  = ClientBuilder::create()->setHosts([$host . ':' . $port])->build();

        $post_params['index'] = 'ivy_user_index';
        $post_params['type'] = 'user_type';
        $post_params['id'] = '8272707';

        $d = $client->delete($post_params);

        dd($d);

        $esUser = new esUser();

        $es_user = $esUser->getByFid('uid',8272707);

        dd($es_user);

        $model = new MyElasticSearch();

//        $d = $model->delete_index();
        //$d = $model->create_index();

//        $d= $model->add_doc(8272519, ['uid'=>8272519, 'moblie'=>'8272519', 'name'=>'8272519你好']);


        $d = $model->update_doc('8272519');

//        $d = $model->get_doc(8272519);
        dd($d);
        $esUser = new esUser();
        $esUser->update_doc(8272519);

        $es_user = $esUser->getByFid('uid',8272519);
        dd($es_user);

        $esUser = new esUser();

        $params_dat['id'] = 8272519;
        $params_dat['uid'] = 8272519;
        $params_dat['mobile'] = 8272519;
        $params_dat['name'] = 8272519;
        $info = $esUser->index($params_dat);
        dd($info);

        $data = $esUser->update_doc([
            'doc'=>[
                'name'=>'tittt'
            ]
        ]);

        $es_user = $esUser->getByFid('uid',8272706);




        dd(getSignUrl('http://ivy-test.oss-cn-shenzhen.aliyuncs.com/png/2567/20181129/2018112999d7366b5714652d0f2052f78d474a28.png'));

        $temp_arr['mid'] = time();
        $temp_arr['title'] = "嘿嘿";
        $temp_arr['description'] = "嘿嘿halouufsd";
        $temp_arr['cover'] = "嘿嘿halouufsd";
        $key = dispatch((new Elesticsearch(['type'=>'2', 'data'=>$temp_arr]))->onQueue('eleasticsearch'));
        dd($key);







        $esUser = new esUser();

        $es_user = $esUser->getByFid('uid',8272706);


        dd($es_user);





        dd(md5('1514,1512,1510,1508,1507,1503,1502,1501,1500'));
        $data = Redis::get("filtr_recommend_log:".md5('1514,1512,1510,1508,1507,1503,1502,1501,1500'));
        dd($data);

        $ossKey = 'a';
        $expires_in = 3600;
        $temp_arr = ['a'=>'a'];

        Redis::setex($ossKey, $expires_in, json_encode($temp_arr));
        Redis::del('a');
        $obj = new Hpush();

        $dadta = $obj->getAccessToken();
        dd($dadta);
        dd(md5('AKl7zPS0noBErD12pcJeCTWDFqHvgZHbrAP7BUSj3jCoDI7ovLFoBGzzZ7JTO4_D2hbDhW5jE_MmhBXWHMoqqilc5saAlGRDrvfVPPj4zXm8NIlEvNc0D8tz_jx9bBxvkQ'));
        dd(Redis::del('a'));
        dd(Redis::set('a', 'a'));

       // Redis::del('a');
exit;
        dd(getSignUrl('http://ivy-test.oss-cn-shenzhen.aliyuncs.com/shareholder_sign/a8c4/20181116/20181116a34ef1bd3d5e87d3daba74e2fe432678.png'));


        $pushData['type'] = 'singlePush';
        $temp_data['title'] = '亲友发布视频';
        $temp_data['content'] = '亲友发布视频';
        $temp_data['description'] = '亲友发布视频';
        $temp_data['msg_type'] = 1;
        $temp_data['notify_foreground'] = 0;
        $temp_data['mobile_list'] = '13165ffa4e26c2b4fc5';
        $pushData['data'] = $temp_data;

        $pushParams = $pushData['data'];

        if(!isset($pushData['type']))
            return ['status'=>'error', 'message'=>'参数异常'];
        $action = $pushData['type'];
        $data = $this->$action($pushData['type'], $pushParams);


        $media_id = 590;

        $media = Media::find($media_id);

        // 关注推送
        if ($media->is_private == '0') {
            $attentionUserList = FriendUser::where([['uid', '=', $media->uid], ['status', '=', '1']])->with('friendUser')->get();
            if ($attentionUserList) {
                // 遍历推送
                foreach ($attentionUserList as $value) {
                    if (!empty($value->friendUser->registration_id)) {
                        $registration_id = $value->friendUser->registration_id;

                        /*Pusher::message($registration_id, '您关注的用户发布了新视频', ['type' => 0]);
                        Pusher::alert($registration_id, '您关注的用户发布了新视频');*/

                        $getPushChannel = JpushMobile::getRowsArray([['registration_id', '=', $registration_id]]);
                        // 消息推送
                        if(!empty($getPushChannel) && !empty($getPushChannel['push_channel_id'])){

                            ////////////////////////////////////////////////////////////////////////////////////////////////
                            // 标题  --app 通过notify id 0处理业务 --透传
                            $data['channel_id'] = $getPushChannel['push_channel_id'];
                            $data['title'] = '您关注的用户发布了新视频'; // 登录标题
                            $data['content'] = '您关注的用户发布了新视频';// 内容
                            $data['description'] = '您关注的用户发布了新视频'; // 描述
                            $data['msg_type'] = 0;  // 消息类型：1通知 0透传
                            $data['notify_id'] = 0;     // 通知id   --app 处理业务标识
                            $data['notify_foreground'] = 0; // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
                            $data['mobile_list'] = $getPushChannel['registration_id'];
                            $data['mobile_unique_code'] = IT('mobile_unique_code');
                            dispatch((new PushQueue(['type'=>'singlePush', 'data'=>$data]))->onQueue('push'));

                            // 发通知提示用户   --通知
                            unset($data['msg_type']);
                            $data['msg_type'] = 1;  // 消息类型：1通知 0透传
                            dispatch((new PushQueue(['type'=>'singlePush', 'data'=>$data]))->onQueue('push'));
                            ////////////////////////////////////////////////////////////////////////////////////////////////
                        }
                    }
                }
            }
        }

        // 亲友圈推送
        if ($media->is_private == 2) {

            $friendList = FriendModel::where([['uid', '=', $media->uid], ['status', '=', '1']])->with('friendUser')->get();
            if(!empty($friendList)){
                foreach ($friendList as $value){
                    if(!empty($value->friendUser->registration_id)){
                        $registration_id = $value->friendUser->registration_id;
                        if ($registration_id) {

                            /*Pusher::message($registration_id, '您的亲友圈好友发布了新视频', ['type' => 1]);
                            Pusher::alert($registration_id, '您的亲友圈好友发布了新视频');*/

                            $getPushChannel = JpushMobile::getRowsArray([['registration_id', '=', $registration_id]]);
                            // 消息推送
                            if(!empty($getPushChannel) && !empty($getPushChannel['push_channel_id'])){

                                ////////////////////////////////////////////////////////////////////////////////////////////////
                                // 标题  --app 通过notify id 0处理业务 --透传
                                $data['channel_id'] = $getPushChannel['push_channel_id'];
                                $data['title'] = '亲友发布视频'; // 登录标题
                                $data['content'] = '您的亲友圈好友发布了新视频';// 内容
                                $data['description'] = '您的亲友圈好友发布了新视频'; // 描述
                                $data['msg_type'] = 0;  // 消息类型：1通知 0透传
                                $data['notify_id'] = 1;     // 通知id   --app 处理业务标识
                                $data['notify_foreground'] = 0; // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
                                $data['mobile_list'] = $getPushChannel['registration_id'];
                                $data['mobile_unique_code'] = IT('mobile_unique_code');
                                dispatch((new PushQueue(['type'=>'singlePush', 'data'=>$data]))->onQueue('push'));

                                // 发通知提示用户   --通知
                                unset($data['msg_type']);
                                $data['msg_type'] = 1;  // 消息类型：1通知 0透传
                                dispatch((new PushQueue(['type'=>'singlePush', 'data'=>$data]))->onQueue('push'));
                                ////////////////////////////////////////////////////////////////////////////////////////////////
                            }
                        }
                    }
                }
            }
        }










        dd(getSignUrl('http://ivy-test.oss-cn-shenzhen.aliyuncs.com/membership/2567/20181114/20181114e59f5df103ac48a075fec227264faf05.text'));
        // 标题
        $data['channel_id'] = '1';
        $data['title'] = '登录';
        // 内容
        $data['content'] = '您的账户在别处登陆';
        // 描述
        $data['description'] = '您的账户在别处登陆';
        // 消息类型：1通知 0透传
        $data['msg_type'] = 0;

        $data['notify_id'] = 4;
        // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
        $data['notify_foreground'] = 0;
        /*$data['bi_tag'] = $city;
        $data['icon'] = $city;*/
        $data['mobile_list'] = '11111111';
        $data['mobile_unique_code'] = IT('mobile_unique_code');

        $result = dispatch((new LogQueue(['type'=>'singlePush', 'data'=>$data]))->onQueue('push'));


        dd($result);







        $pushObj = new Push();
        // 区分应用渠道推送
        $data = $pushObj->initInstance(['channel_id'=>1]);

        // 移动设备
        $mobile_list[] = '101d85590969c7eebe4';
        $post_params['title'] = '标题';
        $post_params['content'] = '内容';
        $post_params['description'] = '通知描述';
        // 消息类型：通知，透传
        $post_params['msg_type'] = 0;

        // 发送业务id ，id的作用，同一重复发送覆盖，具体结合推送平台文档操作
        $post_params['notify_id'] = 4;
        // 可选项
        // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
        $post_params['notify_foreground'] = 0;
        $post_params['bi_tag'] = 'tag 标签';
        $post_params['icon'] = '图标链接地址';
        $post_params['mobile_list'] = $mobile_list;

        $data = $pushObj->singlePush($post_params);
        dd($data);


        $url = 'http://ivy-test.oss-cn-shenzhen.aliyuncs.com/4389/201810/2018101145ce55e40cdaf74735702414582e572b.mp4';
        // $url = 'http://ivy-test.oss-cn-shenzhen.aliyuncs.com/74e5/201810/20181018510d6e7e5d166276ca6e7dc8add2b715.mp4';
        $url = getSignUrl($url);

        dd($url);


        $data['uid'] = 1;
        $data['media_id'] = 2;
        $data['action'] = 3;
        $data['duration'] = time();
        Behavior::write($data['uid'], $data['media_id'], $data['action'], $data['duration']);

        // 队列
        dispatch((new LogQueue(['type'=>'tuijian', 'data'=>$data]))->onQueue('log_queue'));
        exit;

        $post_params = $request->all();

        $url = 'http://ivy-test.oss-cn-shenzhen.aliyuncs.com/membership/a8c4/20181105/201811055e9724f3224f8e8a5b145c6be4cf88e9.text';
        // $url = 'http://ivy-test.oss-cn-shenzhen.aliyuncs.com/74e5/201810/20181018510d6e7e5d166276ca6e7dc8add2b715.mp4';
        $url = getSignUrl($url);

        dd($url);


        /*txt 简单文件上传
        */
        // 阿里云主账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维，请登录 https://ram.console.aliyun.com 创建RAM账号。
        $accessKeyId = "LTAIpijo8qUp3wav";
        $accessKeySecret = "gU40FGuyotObUVuvS625ESxG1D7v2r";
        // Endpoint以杭州为例，其它Region请按实际情况填写。
        $endpoint = "http://oss-cn-shenzhen.aliyuncs.com";
        // 存储空间名称
        $bucket= "ivy-test";
        // 文件名称
        $object = "blake/test".time();
        // <yourLocalFile>由本地文件路径加文件名包括后缀组成，例如/users/local/myfile.txt
        $filePath = base_path('storage/touxiang/82725262018110274e8c88831ef45d7456834f8bf88735f.txt');

        try{
            $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint);

            $ossClient->uploadFile($bucket, $object, $filePath);
        } catch(OssException $e) {
            printf(__FUNCTION__ . ": FAILED\n");
            printf($e->getMessage() . "\n");
            return;
        }
        print(__FUNCTION__ . ": OK" . "\n");



        $filename = time();
        $file = base_path('storage/touxiang/'.$filename.'.txt');
        file_put_contents($file, isset($post_params['certificate']) ? $post_params['certificate'] : 'post', FILE_APPEND);

        return json_success('ok', []);

        $media_id = '387';
        $media = Media::find($media_id);
        // 获取视频地址
        $url = getSignUrl('http://ivy-pro.oss-cn-shenzhen.aliyuncs.com/5b46/201810/20181022225601dbdac2a456b8b385735c0e4519.mp4');

        dd($url);
        dd(cache('origin_oss_url'));

        for($i=0;$i<100;$i++){
            $data[] = $i;
            cache(['origin_oss_url' => $data], 36000);
        }

        dd('a');
        $media_id = '387';
        $media = Media::find($media_id);
        // 获取视频地址
        $url = getSignUrl('http://ivy-test.oss-cn-shenzhen.aliyuncs.com/dcbc/201810/2018101786794453f6ccd4da1efd791a27c53c60.png');
        dd($url);



        /*$error[] = 11111;
        $pushData[] = 2222;

        $data = Log::do_log(['message'=>implode(',', $error), 'push_data'=>$pushData, 'action_push_data'=>''], 'test', 'test');
        dd($data);
        // 推送信息到队列中 //设置队列别名
        dispatch((new PushQueue(['a1'=>1]))->onQueue('push'));

        $redis = new Redis();
        dd($redis);

        dd(cache('weixin_jssdk_sign'));

        $key = cache([''=>[1,2,3,4,5,6]],7190);
        dd($key);

        $key = Redis::set('a', 'a');
        dd($key);*/

        $uid = D('user_tickets')->where(['id'=> 667105])->value('uid');

        dd($uid);


        $pushObj = new Push();
        // 区分应用渠道推送
        $data = $pushObj->initInstance(['channel_id'=>1]);

        $mobile_list[] = '120c83f76071b044f28';
        $post_params['title'] = '标题';
        $post_params['content'] = '内容';
        $post_params['description'] = '通知描述';
        // 消息类型：通知，透传
        $post_params['msg_type'] = 1;

        // 发送业务id ，id的作用，同一重复发送覆盖，具体结合推送平台文档操作
        $post_params['notify_id'] = 4;
        // 可选项
        // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
        $post_params['notify_foreground'] = 0;
        $post_params['bi_tag'] = 'tag 标签';
        $post_params['icon'] = '图标链接地址';
        $post_params['mobile_list'] = $mobile_list;

        $data = $pushObj->batchPush($post_params);
        dd($data);


        /*dd(EE('测试',1000));

        $uid = D('user_tickets')->where(['id'=> 8272526])->value('uid');

        dd($uid);*/

        // 消息推送集成
        // 小米推送
        $pushObj = new PushService();
        // 区分应用渠道推送
        $data = $pushObj->initInstance(['channel_id'=>3]);

        $mobile_list[] = '1a1018970af35e9d8ab';
        $post_params['title'] = '标题';
        $post_params['content'] = '内容';
        $post_params['description'] = '通知描述';
        // 消息类型：通知，透传
        $post_params['msg_type'] = 1;

        // 发送业务id ，id的作用，同一重复发送覆盖，具体结合推送平台文档操作
        $post_params['notify_id'] = 1;
        // 可选项
        // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
        $post_params['notify_foreground'] = 1;
        $post_params['bi_tag'] = 'tag 标签';
        $post_params['icon'] = '图标链接地址';
       $post_params['mobile_list'] = $mobile_list;


//       $data = $pushObj->singlePush($post_params);

       $data = $pushObj->batchPush($post_params);

       dd($data);


        /*// 极光推送
        $pushObj = new Push();
        // 区分应用渠道推送
        $data = $pushObj->initInstance(['channel_id'=>1]);

        $mobile_list[] = '1a1018970af35e9d8ab';
        $post_params['title'] = '标题';
        $post_params['content'] = '内容';
        $post_params['description'] = '通知描述';
        // 消息类型：通知，透传
        $post_params['msg_type'] = 1;

        // 发送业务id ，id的作用，同一重复发送覆盖，具体结合推送平台文档操作
        $post_params['notify_id'] = 4;
        // 可选项
        // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
        $post_params['notify_foreground'] = 1;
        $post_params['bi_tag'] = 'tag 标签';
        $post_params['icon'] = '图标链接地址';
        $post_params['mobile_list'] = $mobile_list;

        $data = $pushObj->batchPush($post_params);
        dd($data);*/

        // 华为推送
        $pushObj = new Push();
        // 区分应用渠道推送
        $data = $pushObj->initInstance(['channel_id'=>2]);

        $mobile_list[] = '0864100035178451300002495900CN01';
        $post_params['title'] = '标题';
        $post_params['content'] = '内容';
        $post_params['description'] = '通知描述';
        // 消息类型：通知，透传
        $post_params['msg_type'] = 1;

        // 发送业务id ，id的作用，同一重复发送覆盖，具体结合推送平台文档操作
        $post_params['notify_id'] = 4;
        // 可选项
        // 开启/关闭app在前台时的通知弹出 1:弹出通知  0 不弹出
        $post_params['notify_foreground'] = 1;
        $post_params['bi_tag'] = 'tag 标签';
        $post_params['icon'] = '图标链接地址';
        $post_params['mobile_list'] = $mobile_list;
        $post_params['action_type'] = 3;

        $data = $pushObj->batchPush($post_params);
        dd($data);

       /*// 华为推送
       $pushObj = new Push();
       // 区分应用渠道推送
       $data = $pushObj->initInstance(['channel_id'=>2]);

       $post_params['title'] = '标题';
       $post_params['content'] = '内容';
       /*$post_params['bi_tag'] = '什么标签tag';
       $post_params['icon'] = '消息图标链接地址';*/
        $deviceTokens[] = '0864100035178451300002495900CN01';
        $post_params['deviceTokens'] = $deviceTokens;
        $post_params['meg_type'] = 3;
        $post_params['action_type'] = 3;


        $data = $pushObj->batchPush($post_params);

//        dd($data);
        $pushObj->singlePush();

        dd($data);

        /*// redis 测试
        $key = Redis::set('a', 'a');
        dd($key);*/


        /*
         * 事件/监听 测试
         * $data = [
            'expire_time' => date('Y-m-d H:i:s', time() + 300),
        ];

        $event = event(new PushEvent($data));
        dd($event);*/


        // 推送信息到队列中
        dispatch(new PushQueue(['a'=>'a']));

        return json_success('ok', []);
    }

    public function que()
    {
        dispatch(new PushQueue(['a'=>'a']));
        dd('a');
    }

    /**
     * @desc 环信状态
     */
    public function hx_user_status() {
        $id = IT('id', true, '请输入微影号');
        $is_record = HxUsers::where(['uid' => $id , 'hx_activated' => 1, 'status' => 1])->first();
        if(!$is_record) {
            echo "该微影号没有环信账号";
            return false;
        }
        $hx_im = new Hxim();
        $get_hx_user_url = $hx_im->base_url.'/'.$hx_im->org_name.'/'.$hx_im->app_name.'/users/'.$is_record->hx_username.'/status';
        $hx_user_data = $hx_im->curl_get_json($get_hx_user_url);
        print_r($hx_user_data);exit;

    }
}